<?php
session_start();
//包含头
include '../PHP/head.php';
?>
<?php
//包含bootstrap的顶端按钮
include '../PHP/menu.php';
?>

<br />
<br />
<p class="text-center lead">各专业情况</p>
<?php
//接收操作
if (isset($_GET['sent'])) {
	$clarification_id = $_GET['clarification_id'];
	require_once ('../FNS/db_fns.php');
		
		$db = db_connect();
		
		$query="update clarification set status = '发出' where id = '".$clarification_id."'";
		$result=$db->query ($query);
		if ($result){
			echo "<br />";
			echo "<p>发出设置成功。</p>";
		}else{
			echo "<br />";
			echo"<p>发出设置失败！</p>";
	
		$db->close();
		}
	
}

if (isset($_GET['back'])) {
	//填写客户澄清回复
	$clarification_id = $_GET['clarification_id'];
	$project_id = $_GET['project_id'];
	
	echo "
	<form class='form-horizontal' action = '../PHP/show_clarification_checked.php' method = 'get'>
		<input type='hidden' name = 'project_id' value = '".$project_id."'>
		<input type='hidden' name = 'clarification_id' value = '".$clarification_id."'>
		<div class='form-group'>
			<label for='client_resp' class='col-md-2 control-label'>客户回复：</label>
			<div class='col-md-10'>
				<textarea class='form-control' rows='2' name='client_resp'></textarea>
			</div>
		</div>
		<br />
		<div class='form-group'>
			<div class='col-md-offset-2 col-md-3'>
				<input class='btn btn-success' type = 'submit' value='填入回复'/>
			</div>
		</div>
	</form>
	";
}

if (isset($_GET['client_resp'])) {
	//客户回复写入数据库
	$clarification_id = $_GET['clarification_id'];
	$client_resp = $_GET['client_resp'];
	
	//数据过滤和处理
	//加引号避免输入数据库出错
	if (! get_magic_quotes_gpc()) {	
	$clarification_id = addslashes ($clarification_id);
	$client_resp = addslashes ($client_resp);
	}
	
	$resp_date = date('Y-m-d');
	
	require_once ('../FNS/db_fns.php');
		
	$db = db_connect();
		
	$query="update clarification set status = '回复', client_resp = '".$client_resp."', resp_date = '".$resp_date."' where id = '".$clarification_id."'";
	
	$result=$db->query ($query);
		if ($result){
			echo "<br />";
			echo "<p>填写成功。</p>";
		}else{
			echo "<br />";
			echo"<p>填写失败！</p>";
	
		}
		//专业状态改回"1" - 进行中。
		$query="select project_id, subject from clarification where id = '".$clarification_id."'";
		$result=$db->query ($query);
		$row=$result->fetch_assoc ();
		$project_id = $row['project_id'];
		$subject = stripslashes ($row['subject']);
		
		$result->free();
		
		$query="update projects set ".$subject."_flag = '1' where id = '".$project_id."'";
		$result=$db->query ($query);
		
		$db->close();
	
}



if (isset($_GET['project_id'])) {
//接收GET过来的project_id，从projects表里搜出该项目
require_once ('../FNS/db_fns.php');

$project_id = $_GET['project_id'];

$db = db_connect();
$query="select projects.code as project_code, projects.name as project_name, projects.sale as sale_id, projects.entrust_date, ei_flag, st_flag, pi_flag, ve_flag, me_flag, users.name as sale_name from projects inner join users on projects.sale = users.id where projects.id = '".$project_id."'";
	
$result=$db->query ($query);
$num_result=$result->num_rows;
	
//拿出数据
$row=$result->fetch_assoc ();
$project_code = stripslashes ($row['project_code']);
$project_name = stripslashes ($row['project_name']);
$sale_name = stripslashes ($row['sale_name']);
$sale_id = stripslashes ($row['sale_id']);

$ei_flag = stripslashes ($row['ei_flag']);
$st_flag = stripslashes ($row['st_flag']);
$pi_flag = stripslashes ($row['pi_flag']);
$ve_flag = stripslashes ($row['ve_flag']);
$me_flag = stripslashes ($row['me_flag']);
	
$result->free();
	
//列出编号基本信息
echo "
	<br />
	<div class='row'>
		<div class='col-md-2'><p class='text-right'>报价编号：</p></div>
		<div class='col-md-2'><p>".$project_code."</p></div>
		<div class='col-md-2'><p class='text-right'>项目名称：</p></div>
		<div class='col-md-4'><p>".$project_name."</p></div>
		<div class='col-md-1'><p class='text-right'>销售：</p></div>
		<div class='col-md-1'><p>".$sale_name."</p></div>
	</div>
	<br />
";
//处理信息状态

$ei_status = subject_status ($ei_flag);
$st_status = subject_status ($st_flag);
$pi_status = subject_status ($pi_flag);
$ve_status = subject_status ($ve_flag);
$me_status = subject_status ($me_flag);


//写表头
echo "<table class='table table-striped'>";
echo "<tr>";
	echo "<td align='center' class='info'><strong>电仪</strong></td>";
	echo "<td align='center' class='info'><strong>结构</strong></td>";
	echo "<td align='center' class='info'><strong>管道</strong></td>";
	echo "<td align='center' class='info'><strong>容器</strong></td>";
	echo "<td align='center' class='info'><strong>机械</strong></td>";
	echo "<td align='center' class='info'><strong>操作</strong></td>";
echo "</tr>";



//循环编制表格
	$link = "../PHP/list_files.php?project_id=".$project_id;
	
	echo "<tr>";
	echo "<td align ='center'>".$ei_status."</td>";
	echo "<td align ='center'>".$st_status."</td>";
	echo "<td align ='center'>".$pi_status."</td>";
	echo "<td align ='center'>".$ve_status."</td>";
	echo "<td align ='center'>".$me_status."</td>";
	echo "<td align='center'><a class='btn btn-success btn-sm' href='".$link."' role='button'>文件列表</a></td>";
	echo "</tr>";
	
echo "</table>";

$db->close();
}
?>




</div>
</body>
</html>